package com.flst;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.EntityTransaction;

import com.google.inject.Inject;

public class JPAAuthorDAO implements AuthorDAO {

	@Inject
	EntityManager em = null;

	public Author saveAuthor(Author author1) {
		EntityTransaction tx = em.getTransaction();

		tx.begin();
		Author ret = em.merge(author1);
		tx.commit();
		return ret;
	}

	public Author getAuthor(Integer idAuthor) {

		return em.find(Author.class, idAuthor);

	}

	@SuppressWarnings("unchecked")
	public List<Author> getAllAuthors() {
		// TODO Auto-generated method stub

		return em.createQuery("FROM Author").getResultList();
	}

}
